package RSA

import (
	"crypto/rsa"
)

func GenerateKeyPEM() (string, string, error) {
	return generateKeyPEM()
}

func GenerateKeyFile(privateFileName, publicFileName string) error {
	return generateKeyFile(privateFileName, publicFileName)
}

func SaveKeyFile(privateKey *rsa.PrivateKey, privateFileName, publicFileName string) error {
	return saveKeyFile(privateKey, privateFileName, publicFileName)
}

func SavePublicKeyToFile(publicKey *rsa.PublicKey, filename string) error {
	return savePublicKeyToFile(publicKey, filename)
}

func SavePrivateKeyToFile(privateKey *rsa.PrivateKey, filename string) error {
	return savePrivateKeyToFile(privateKey, filename)
}

func LoadPrivateKeyFromFile(filename string) (*rsa.PrivateKey, error) {
	return loadPrivateKeyFromFile(filename)
}

func LoadPublicKeyFromFile(filename string) (*rsa.PublicKey, error) {
	return loadPublicKeyFromFile(filename)
}

func EncryptByPublicKey(publicKey *rsa.PublicKey, data []byte) ([]byte, error) {
	return encryptByPublicKey(publicKey, data)
}

func DecryptByPrivateKey(privateKey *rsa.PrivateKey, data []byte) ([]byte, error) {
	return decryptByPrivateKey(privateKey, data)
}

// PrivateKeyToPEMString 将RSA私钥转换为PEM格式字符串
func PrivateKeyToPEMString(privateKey *rsa.PrivateKey) (string, error) {
	return privateKeyToPEMString(privateKey)
}

// PublicKeyToPEMString 将RSA公钥转换为PEM格式字符串
func PublicKeyToPEMString(publicKey *rsa.PublicKey) (string, error) {
	return publicKeyToPEMString(publicKey)
}

// PrivateKeyFromPEMString 从PEM字符串解析RSA私钥
func PrivateKeyFromPEMString(privateKeyPEM string) (*rsa.PrivateKey, error) {
	return privateKeyFromPEMString(privateKeyPEM)
}

// PublicKeyFromPEMString 从PEM字符串解析RSA公钥
func PublicKeyFromPEMString(publicKeyPEM string) (*rsa.PublicKey, error) {
	return publicKeyFromPEMString(publicKeyPEM)
}
